<template>
  <div class="img-view">
    <i class="iconfont iconguanbi" @click="$emit('cancel')"></i>
    <div class="flex-center img-box">
      <img :src="img" ref="viewImg" />
    </div>
    <div class="scale-btn flex-center">
      <el-button type="info" size="small" @click="scale(0)">
        <i class="iconfont iconfangda"></i>
        <span>放大</span>
      </el-button>
      <el-button type="info" size="small" @click="scale(1)">
        <i class="iconfont iconsuoxiao"></i>
        <span>缩小</span>
      </el-button>
    </div>
  </div>
</template>

<script>
export default {
  props: ["img"],
  data() {
    return {
      scl: 1
    };
  },
  methods: {
    scale(type) {
      type === 0 ? (this.scl += 0.1) : (this.scl -= 0.1);
      this.scl <= 0.1 ? (this.scl = 0.1) : (this.scl = this.scl);
      this.scl >= 2 ? (this.scl = 2) : (this.scl = this.scl);
      this.$refs["viewImg"].style.transform = `scale(${this.scl})`;
    }
  }
};
</script>

<style lang="scss">
.img-view {
  position: fixed;
  z-index: 999;
  height: 100vh;
  width: 100vw;
  top: 0;
  left: 0;
  background: rgb(51, 51, 51);
  .iconguanbi {
    color: #fff;
    font-size: 40px;
    position: absolute;
    right: 20px;
    top: 15px;
    cursor: pointer;
  }
  .img-box {
    height: 100vh;
    img {
      max-width: 1200px;
      max-height: 800px;
    }
  }
  .scale-btn {
    position: absolute;
    top: 15px;
    left: 50%;
    transform: translate(-50%);
    .iconfangda,
    .iconsuoxiao {
      font-size: 14px;
      margin-right: 7px;
    }
    .el-button + .el-button {
      margin-left: 30px;
    }
  }
}
</style>